package com.example.chattingroom.api;

import com.example.chattingroom.model.Message;
import com.example.chattingroom.model.MessageMapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;
@RestController
public class MessageAPI {
    @Resource
    private MessageMapper messageMapper;

    @GetMapping("/message")
    public Object getMessage(int sessionId)
    {
        //根据会话Id在数据库里进行查询，匹配对应的消息列表
        List<Message> messages = messageMapper.getMessageBySessionId(sessionId);

        //
        Collections.reverse(messages);
        return messages;
    }
}
